{include file="public/head"}
    <body>
    <div class="x-body" >

        <div class="lotus-nav layui-row ">
            <button class="layui-btn layui-btn-sm many-tables" onclick="">一键备份</button>
            <button  onclick="show_full('备份列表','backup_list.html')" class="layui-btn layui-btn-sm layui-btn-normal " onclick="">备份列表</button>

            <span class="x-right" >数据库表数量:{$tableNum}
                 <button onclick="javascript:location.reload()" class="layui-btn-default">
                    <i class="icon iconfont">&#xe6aa;</i>
                </button>
            </span>
        </div>

    <table class="layui-table">
        <thead>
          <tr>
            <th>
              <div class="header layui-form-checkbox layui-form-checked" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th>数据表</th>
            <th>记录条数</th>
            <th>占用空间</th>
            <th>编码</th>
            <th>创建时间</th>
            <th>操作</th>
        </thead>
        <tbody>
         {empty name="list"}
                            <tr>
                                <td class="no-data" align="center" axis="col0" colspan="50">
                                    <i class="fa fa-exclamation-circle"></i>没有符合条件的记录
                                </td>
                            </tr>
                        {else/}
                            {foreach name="list" item="vo" key="k" }
                            <tr data-id="{$vo.Name}">
                                <td>
                                      <div data-table-name="{$vo.Name}" class="layui-form-checkbox layui-form-checked" lay-skin="primary" data-id='{$vo.Name}'><i class="layui-icon">&#xe605;</i></div>
                                </td>
                             <!--    <td class="sign">
                                    <div class="w40 tc"><input type="checkbox" name="tables[]" value="{$vo.Name}" checked="checked"></div>
                                </td> -->
                                <td >
                                    <div style="padding-left: 10px;">{$vo.Name}</div>
                                </td>
                                <td>
                                    <div class="w80 tc">{$vo.Rows}</div>
                                </td>
                                <td>
                                    <div class="w80 tc">{$vo.Data_length|format_bytes}</div>
                                </td>
                                <td>
                                    <div class="w120 tc">{$vo.Collation}</div>
                                </td>
                                <td>
                                    <div class="w160 tc">{$vo.Create_time}</div>
                                </td>
                                <td>
                                    <div class="info w80 tc">
                                        <button onclick="optimize('{$vo.Name}')" class="layui-btn layui-btn-success layui-btn-xs">优化</button>
                                        <button  onclick="repair('{$vo.Name}')" class="layui-btn layui-btn-normal layui-btn-xs">修复</button>
                                    </div>
                                </td>
                            </tr>
                            {/foreach}
                        {/empty}
        </tbody>
      </table>
	    
    </div>
</body>
{include file="public/foot"}
<script type="text/javascript">
    $(function(){



       $(".many-tables").click(function(event) {
         //询问框
        layer.confirm('是否确认备份？', {
          btn: ['确定','取消'] //按钮
        }, function(){
             var data = tableCheck.getData();
        backup(data);
        });

       
       });
    })
    //备份数据库
    function backup(tables){
        layer.load();
        $.ajax({
            url: "{:url('admin/db_manage/backup')}",
            type: 'post',
            dataType: 'json',
            data: {tables: tables},
        })
        .done(function(data) {
            layer.closeAll('loading');
            if(data.msg!==0){
                layer.alert(data.msg);
            }else{
                layer.msg('备份失败');
            }
        })
        
    }


    function optimize(table_name){
        layer.load();
        $.ajax({
            url: "{:url('admin/db_manage/optimize')}",
            type: 'post',
            dataType: 'json',
            data: {table_name: table_name},
        })
        .done(function(data) {
            layer.closeAll('loading');
            if(data.msg!==0){
                layer.alert(data.msg);
            }else{
                layer.msg('失败');
            }
        }) 
    }

    function repair(table_name){
        layer.load();
        $.ajax({
            url: "{:url('admin/db_manage/repair')}",
            type: 'post',
            dataType: 'json',
            data: {table_name: table_name},
        })
        .done(function(data) {
            layer.closeAll('loading');
            if(data.msg!==0){
                layer.alert(data.msg);
            }else{
                layer.msg('失败');
            }
        }) 
    }


</script>
